#include "common.h"

class Solution
{
public:
    int longestOnes(vector<int> &nums, int k)
    {
        int len = 0;
        int left = 0, right = 0;
        int sz = nums.size();

        int allow = k;
        for(;; ++right)
        {
            if(nums[right] == 0)
            {
                --allow;
            }
            while(allow < 0)
            {
                if(nums[left++] == 0) ++allow;
            }
            len = max(len,right - left + 1);
        }
        return len;
    }
};